import 'dart:convert' show json;

import 'package:flutter_common_app/data/protection.dart';

class UserLevelData {
  UserLevelData({
    this.userId,
    this.info,
    this.progress,
    this.nextPlayCount,
    this.nextLoginCount,
    this.nowPlayCount,
    this.nowLoginCount,
    this.level,
  });

  factory UserLevelData.fromJson(Map<String, dynamic> jsonRes) =>
      jsonRes == null
          ? null
          : UserLevelData(
        userId: asT<int>(jsonRes['userId']),
        info: asT<String>(jsonRes['info']),
        progress: asT<double>(jsonRes['progress']),
        nextPlayCount: asT<int>(jsonRes['nextPlayCount']),
        nextLoginCount: asT<int>(jsonRes['nextLoginCount']),
        nowPlayCount: asT<int>(jsonRes['nowPlayCount']),
        nowLoginCount: asT<int>(jsonRes['nowLoginCount']),
        level: asT<int>(jsonRes['level']),
      );

  int userId;
  String info;
  double progress;
  int nextPlayCount;
  int nextLoginCount;
  int nowPlayCount;
  int nowLoginCount;
  int level;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'userId': userId,
    'info': info,
    'progress': progress,
    'nextPlayCount': nextPlayCount,
    'nextLoginCount': nextLoginCount,
    'nowPlayCount': nowPlayCount,
    'nowLoginCount': nowLoginCount,
    'level': level,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}
